const express = require('express');
const router = express.Router();
const certificateController = require('../controllers/certificateController');
const auth = require('../middleware/auth');

// 公开接口
router.get('/view/:certNumber', certificateController.getCertificate);

// 检查证书编号是否存在（需要认证）
router.get('/check/:certNumber', auth, certificateController.checkCertNumber);

// 需要认证的接口
router.get('/', auth, certificateController.getCertificates);
router.post('/', auth, certificateController.createCertificate);
router.put('/:id', auth, certificateController.updateCertificate);
router.delete('/:id', auth, certificateController.deleteCertificate);
router.get('/:id/qrcode', auth, certificateController.downloadQRCode);
router.post('/batch-download', auth, certificateController.batchDownloadQRCode);

// 重新生成二维码
router.post('/:id/regenerate-qrcode', auth, certificateController.regenerateQRCode);

// 切换证书状态
router.patch('/:id/toggle-status', auth, certificateController.toggleStatus);

module.exports = router; 